﻿package {
	import flash.errors.IllegalOperationError;
	import flash.utils.Timer;
	import org.flixel.*;
	
	public class Enemy extends Ship	{
		public static const attack_state:int  = 10;
		public static const runaway_state:int = 11;
		public static const comming_state:int = 12;
		public static const waiting_state:int = 13;
		
		public static const from_left:int   = 20;
		public static const from_right:int  = 21;
		public static const from_center:int = 22;
		
		protected var _curr_state:int;
		protected var _curr_from:int;		
		protected var _shot_velocity:FlxPoint;
		protected var _base_velocity:FlxPoint;
		protected var _t_timer:Timer;
		protected var _shot_time:int;
	    protected var _prize:int;

		public function Enemy(state:int,from:int,x:int,y:int) {
			super(x, y);
			_curr_state = state;
			_curr_from = from;
			_shot_velocity = new FlxPoint(0,0);
			_base_velocity = new FlxPoint(0,0);
            _prize = 0;
		}

        public function getPrize():int {
            return _prize;
        }

		public function changeFrom(new_from:int):void {
			_curr_from = new_from;
			switch(new_from) {
				case from_left:
					doFromLeft();
					break;
				case from_right:
					doFromRight();
					break;
				case from_center:
					doFromCenter();
					break;
				default:
					doFromCenter();
					break;
			}
		}
		
		public function changeState(new_state:int):void {
			_curr_state = new_state;
			switch(new_state) {
				case attack_state:
					doAttackState();
					break;
				case runaway_state:
					doRunawayState();
					break;
				case comming_state:
					doCommingState();
					break;
				case waiting_state:
					doWaitingState();
					break;					
				default:
					doAttackState();
					break;
			}
		}
		
		protected function doAttackState():void {}
		
		protected function doRunawayState():void {}
		
		protected function doCommingState():void {}
		
		protected function doWaitingState():void { }
		
		
		protected function doFromLeft():void {}
		
		protected function doFromRight():void {}		
		
		protected function doFromCenter():void {}
		
		
		protected function onAttackState():void {}
		
		protected function onRunawayState():void {}
		
		protected function onCommingState():void { }
		
		protected function onWaitingState():void { }
		
		
		protected function onFromLeft():void {}
		
		protected function onFromRight():void {}		
		
		protected function onFromCenter():void {}
		
		override public function update():void {
			super.update();			
			switch(_curr_state) {
				case attack_state:
					onAttackState();
					break;
				case runaway_state:
					onRunawayState();
					break;
				case comming_state:
					onCommingState();
					break;
				case waiting_state:
					onWaitingState();
					break;					
				default:
					onAttackState();
					break;
			}
			
			switch(_curr_from) {
				case from_left:
					onFromLeft();
					break;
				case from_right:
					onFromRight();
					break;
				case from_center:
					onFromCenter();
					break;
				default:
					onFromCenter();
					break;
			}
		}
	}
}
